//
//  XMLParsing.m
//  JackSMS-Iphone
//
//  Created by Daniele Ciriello on 23/11/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "XMLParsing.h"


@implementation XMLParsing




+(NSString *)firstCheckUser: (NSString *)guest{
	
	NSString *path = [NSString stringWithFormat:@"http://q.jacksms.it/%@/firstCheckUser?xml", guest];
	//converto il fil e un una NSURL
	NSURL *xmlURL = [[NSURL alloc] initWithString:path];
	//creo il parser
	NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
	//il delegato è la classe stessa
	[parser setDelegate:self];
	BOOL success = [parser parse];
	if (success==YES) {
		//rilasciamo il parser*/
		
		return @"yeah";
	}else {
		//rilasciamo il parser*/
		return @"error";
	}
	[parser release];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
	
    if ( [elementName isEqualToString:@"provider"]) {
        // addresses is an NSMutableArray instance variable
        if (!provider)
            provider = [[NSMutableArray alloc] init];
        NSString *thisType = [attributeDict objectForKey:@"type"];
		//NSString *thisOwner = [attributeDict objectForKey:@"owner"];
        if (thisType)
            //[self setType:thisType forProvider:provider];
        return;
    }
	/*
    if ( [elementName isEqualToString:@"person"] ) {
        // currentPerson is an ABPerson instance variable
        currentPerson = [[ABPerson alloc] init];
        return;
    }
	
    if ( [elementName isEqualToString:@"lastName"] ) {
        [self setCurrentProperty:kABLastNameProperty];
        return;
    }
    // .... continued for remaining elements ....*/
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    if (!currentStringValue) {
        // currentStringValue is an NSMutableString instance variable
        currentStringValue = [[NSMutableString alloc] initWithCapacity:50];
    }
    [currentStringValue appendString:string];
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    // ignore root and empty elements
    if ( [elementName isEqualToString:@"provider"] ) return;
	
  
    // ... here ABMultiValue objects are dealt with ...
	
    // currentStringValue is an instance variable
    [currentStringValue release];
    currentStringValue = nil;
}

@end

